<%--
  Created by IntelliJ IDEA.
  User: wkk
  Date: 2022/5/4
  Time: 15:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>登录成功页面</title>
</head>

<script src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css">

<style>
    .input-group{
        width: 80%;
        padding-left: 10%;
    }

</style>
<body>
<h1>登录成功，欢迎${sessionScope.user.name}</h1>

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">添加用户</button>

<form action="${pageContext.request.contextPath}/userAll/search" method="post">
    <input type="text" name="name" class="input-lg" placeholder="请输入你要搜索的名字" >
    <button type="submit" class="btn btn-primary btn-lg" style="margin-top: -5px"><span class="glyphicon glyphicon-search"></span> </button>
</form>

<table class="table table-striped table-hover">
    <tr>
        <th>ID</th>
        <th>名字</th>
        <th>性别</th>
        <th>出生日期</th>
        <th>注册日期</th>
        <th colspan="2">操作</th>
    </tr>
    <c:forEach items="${pageInfo.list}" var="u">
        <tr>
            <td>${u.id}</td>
            <td>${u.name}</td>
            <td>${u.sex}</td>
            <td><fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${u.birthday}"></fmt:formatDate></td>
            <td><fmt:formatDate pattern="yyyy-MM-dd HH:mm:ss" value="${u.registTime}"></fmt:formatDate></td>
            <td>
                <a href="${pageContext.request.contextPath}/userAll/selectOne?id=${u.id}" class="btn btn-success">修改</a>
                <a href="${pageContext.request.contextPath}/userAll/delete?id=${u.id}" class="btn btn-success">删除</a>
            </td>
        </tr>
    </c:forEach>
</table>

<ul class="pager">
    <c:forEach items="${pageInfo.navigatepageNums}" var="page">
        <li>
            <a href="${pageContext.request.contextPath}/userAll/page?pageIndex=${page}">${page}</a>
        </li>
    </c:forEach>
</ul>



<!-- 添加模态框（Modal） -->
<form action="${pageContext.request.contextPath}/userAll/add" method="post">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">添加用户</h4>
            </div>
<%--            模态框主题--%>
            <div class="modal-body">

                <div class="input-group" style="">
                    <label class="input-group-addon">名字：</label>
                    <input type="text" name="name" class="form-control"><br/>
                </div>
                <br>
                <div class="input-group">
                    <label class="input-group-addon">密码：</label>
                    <input type="password" name="password" class="form-control"><br/>
                </div>
                <br/>
                <div class="input-group">
                        <label>性别：</label>
                        <input type="radio" name="sex" value="男"style="margin-left: 30%">男
                        <input type="radio" name="sex" value="女"style="margin-left: 30%">女
                    <br/>
                </div>
                <br/>
                <div class="input-group">
                    <label class="input-group-addon">出生日期：</label>
                    <input type="date" name="birthday" class="form-control"><br/>
                </div>
                <br/>
            </div>
<%--            模态框脚注--%>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <input type="submit" class="btn btn-primary" value="提交" />
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
</form>




<span style="color: red">${error}</span><br/>

<%--&lt;%&ndash;上传文件&ndash;%&gt;--%>
<%--<form action="${pageContext.request.contextPath}/upload2" enctype="multipart/form-data" method="post">--%>
<%--    <div class="input-group">--%>
<%--        <label class="input-group-addon">请选择要上传的图片</label>--%>
<%--        <input type="file" name="files" class="btn btn-info " style="width: 20%;">--%>
<%--    </div>--%>
<%--    <br/>--%>
<%--    <div class="input-group">--%>
<%--        <label class="input-group-addon">请选择要上传的图片</label>--%>
<%--        <input type="file" name="files" class="btn btn-info " style="width: 20%;">--%>
<%--    </div>--%>
<%--    <br/>--%>
<%--    <div class="input-group">--%>
<%--        <label class="input-group-addon">请选择要上传的图片</label>--%>
<%--        <input type="file" name="files" class="btn btn-info " style="width: 20%;">--%>
<%--    </div>--%>
<%--    <br/>--%>
<%--    <input type="submit" value="提交" class="btn btn-primary">--%>
<%--</form>--%>
<%--<hr/>--%>





<%--<c:forEach items="${list}" var="l">--%>
<%--    <a href="${pageContext.request.contextPath}/upload/${l}">${l}</a>--%>
<%--    <a href="${pageContext.request.contextPath}/download?filename=${l}">下载</a>--%>
<%--    <br/>--%>
<%--</c:forEach>--%>

<%--模拟增删改查  REST 风格--%>
<%--<button id="showAll" type="button" class="btn btn-primary">查询全部</button>--%>
<%--<button id="selectOne" type="button" class="btn btn-primary">查询单个</button>--%>
<%--<button id="add" type="button" class="btn btn-primary">添加</button>--%>
<%--<button id="update" type="button" class="btn btn-primary">修改</button>--%>
<%--<button id="delete" type="button" class="btn btn-primary">删除</button>--%>

<script>
    $(function (){
        $("#showAll").click(function () {
            $.ajax({
                url: "${pageContext.request.contextPath}/users",
                type: "get",
                contentType: "application/json",
                success : function (res){
                    console.log(res)
                }
            });
        });


        $("#selectOne").click(function () {
            $.ajax({
                url: "${pageContext.request.contextPath}/users/1",
                type: "get",
                contentType: "application/json",
                success : function (res){
                    console.log(res)
                }
            });
        });

        $("#add").click(function () {
            $.ajax({
                url: "${pageContext.request.contextPath}/users",
                type: "post",
                contentType: "application/json",
                data:JSON.stringify({id:1,name:"王五",password:"1234"}),
                success : function (res){
                    console.log(res)
                }
            });
        });

        $("#update").click(function () {
            $.ajax({
                url: "${pageContext.request.contextPath}/users",
                type: "put",
                contentType: "application/json",
                data:JSON.stringify({id:1,name:"王五",password:"1234"}),
                success : function (res){
                    console.log(res)
                }
            });
        });


        $("#delete").click(function () {
            $.ajax({
                url: "${pageContext.request.contextPath}/users/1",
                type: "delete",
                contentType: "application/json",
                success : function (res){
                    console.log(res)
                }
            });
        });
    });
</script>
</body>
</html>
